<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
</html>
<script>
// for in 循环

/* for 循环 数组
  var arr = ['a', 1, 2, 3, 'b'];

  for (var index = 0; index < arr.length; index++) {
    var element = arr[index];
    console.log(element);
  }
*/

var obj = {
  name: '张三',
  age: 36
}

// for ... in; 
  // for (var key in obj) -> key 为 遍历对象的 属性名

/* 案例：循环 对象 - obj
  for (var key in obj) {
    var element = obj[key];
    console.log('key', key);
    console.log('element', element);
  }
*/

// 测试：for in 能 遍历数组吗
  // for in 遍历数组时， key 为 数组的 下标
var arr = ['a', 1, 2, 3, 'b'];

for (var key in arr) {
  console.log('key', key);
  var element = arr[key];
  console.log('element', element);
}
</script>